#include "stdafx.h"
#include "Bullets.h"

void CBullets::CreateBullet(float fRadius, float fLifeSpan, float fSpeed, int nType, vec3f *vPos, vec3f* vForward)
{
	this->m_fLifeSpan = fLifeSpan;
	this->m_pCollision = new Sphere();
	this->m_fSpeed = fSpeed;
	this->m_vForward = vForward;
	this->m_nType = nType;
	this->m_vPosition = vPos;
	this->m_pCollision->Create(*m_vPosition, fRadius);

	//Temp Damage
	this->m_nDamage = 3;
}

void CBullets::Render()
{
	glPushMatrix();
	{
		glTranslatef(this->m_vPosition->x, m_vPosition->y, m_vPosition->z);
		this->m_pCollision->Render();
	}
	glPopMatrix();
}

void CBullets::Update(float fDeltaTime)
{
	//Update Position
	this->m_vPosition->x += fDeltaTime*m_fSpeed*this->m_vForward->x;
	this->m_vPosition->y += fDeltaTime*m_fSpeed*this->m_vForward->y;
	this->m_vPosition->z += fDeltaTime*m_fSpeed*this->m_vForward->z;

	//Set this position to the collision sphere's position
	this->m_pCollision->m_vCenter.x = this->m_vPosition->x;
	this->m_pCollision->m_vCenter.y = this->m_vPosition->y;
	this->m_pCollision->m_vCenter.z = this->m_vPosition->z;
	
	//LifeSpan
	this->m_fLifeSpan -= fDeltaTime;
}

void CBullets::DestroyBullet()
{
	delete this->m_vPosition;
	delete this->m_vForward;
	this->m_pCollision->Delete();
	delete this->m_pCollision;
}